package com.atguigu.crowd.mvc.handler;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.service.api.AdminService;
import com.atguigu.crowd.util.CrowdUtil;
import com.atguigu.crowd.util.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TestHandler {
    @Autowired
    private AdminService adminService ;
    private Logger logger = LoggerFactory.getLogger(TestHandler.class);
    @RequestMapping("test/ssm.html")
    public String testSsm(ModelMap modelMap,HttpServletRequest request){
        boolean requestType = CrowdUtil.judgeRequestType(request);
        logger.info("requestType"+requestType);
        List<Admin> adminList = adminService.getAll() ;
        modelMap.addAttribute("adminList",adminList) ;
        System.out.println(10/0);
      //  System.out.println(new Student().getAddress().getCity().trim());
        return "target" ;
    }
    @ResponseBody
    @RequestMapping("send/arrayOne.html")
    public String testReceiveArrayOne(@RequestParam("array") List<Integer> array ){
        for(Integer num : array){
            System.out.println("num="+num);
        }
        return "success" ;
    }
    @ResponseBody
    @RequestMapping("send/array/three.html")
    public String testReceiveArrayThree(@RequestBody List<Integer> array){
        for(Integer num : array){
            logger.info("num="+num);
        }
        return "success" ;
    }
}
